from multiprocessing import Pool
import time

def square(x):
    time.sleep(x)  # 模拟任务执行时间
    return x * x

if __name__ == '__main__':
    with Pool(processes=4) as pool:
        start_time = time.time()
        results = pool.map(square, [3, 2, 1, 4, 5])
        for result in results:
            print(result)
        end_time = time.time()
        print()
        print("Total time:", end_time - start_time)


